<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="销售日报表" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doSearch(){
		var startDate=document.getElementById("start_date").value;
		var endDate=document.getElementById("end_date").value;
		var tsId=document.getElementById("ts_id").value;
		
		if(startDate!=null && startDate!=''){
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return;
			}
		}else{
			ShowAlert('提示框','请选择开始日期',200,100);
			return;
		}
		if(endDate!=null && endDate!=''){
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return;
			}
		}else{
			ShowAlert('提示框','请选择结束日期',200,100);
			return;
		}
		
		window.location="/finance/BusinessDateCount.ihtm?start_date="+startDate+"&end_date="+endDate+"&ts_id="+tsId;
	}
	
	function getSearchCondition(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="start_date="+startDate+"&end_date="+endDate+"&ts_id="+tsId;
		return str;
	}
	function doPrint(){
		var str=getSearchCondition();
		showWin(900,600,"/finance/BusinessDateCount.ihtm?content_type=PRINT&"+str);
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function showEstBusCount(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_order_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1024,600,'/business/EstBusinessCount.ihtm?'+str);
	}
	function showEstBackCount(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_order_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1024,600,'/finance/EstBackCount.ihtm?'+str);
	}
	function showRecItemList(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_rece_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1024,600,'/finance/ReceiveBillItemSearchResult.ihtm?'+str);
	}
	function showBackCostList(backType){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_back_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(backType!=null && backType!=""){
			str=str+"&cb_back_type=1&back_type="+backType;
		}
		showWin(1024,600,'/finance/BackCostList.ihtm?'+str);
	}
	function setDate(type){
		var d=new Date();
		var startStr="";
		var endStr="";
		if(type=="CURRENT_MONTH"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-01";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="PREVIEW_MONTH"){
			d=new Date(d.getFullYear(),d.getMonth(),1);
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-1";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="TODAY"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="YESTERDAY"){
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		document.getElementById("start_date").value=startStr;
		document.getElementById("end_date").value=endStr;
	}
</script>
</head>
<c:set var="showLink" value="Y" />
<c:if test="${fn:indexOf(currentUser.privs,';BUSI_SELF;')!=-1 || fn:indexOf(currentUser.privs,';NO_EARL_DATA;')!=-1}">
	<c:set var="showLink" value="N" />
</c:if>
<body class="sheet" style="text-align:center;">
<div class="sheet-main" style="width:860px;text-align:left;margin:auto;">
  <div class="sheet-top">
    <div class="content">
      <h2>销售日报表</h2>
      <p>统计指定期间的合同金额与回款、合同单数、预付单数、结欠单数</p>
    </div>
  </div>
  <div class="sheet-list">
    	<div class="search-business">
	      <div class="content">
	        <table width="100%">
	          <tbody>
	            <tr>
	              <td align="right">
					日期：
					<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" id="start_date" name="start_date" value="${startDate}">
					<img src="/images/calendar.gif" style="cursor:pointer" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this);">
					至<input class="TextBox Datetime" type="text" maxlength="15" onKeyUp="checkInput();" id="end_date" name="end_date" value="${endDate}">
					<img src="/images/calendar.gif" style="cursor:pointer" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this);">											
					<a href="javascript:setDate('CURRENT_MONTH');">本月</a>
					<a href="javascript:setDate('TODAY');">今天</a>
					<a href="javascript:setDate('YESTERDAY');">昨天</a>
					<a href="javascript:setDate('PREVIEW_MONTH');">上月</a>
					<select name="ts_id" id="ts_id">
						<option value="0">==请选择帐套==</option>
						<c:forEach var="item" items="${tsList}">
							<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
						</c:forEach>
		  			</select>
					<input type="button"  value=" 查 询" onClick="doSearch();"  class="buttom search-but">
					<input type="button"  value=" 打 印" onClick="doPrint();"  class="buttom search-print">
				   </td>
	            </tr>    
	            </tbody>      
	        </table>      	 
	      </div>

	      <div class="table-list">					
			  <table width="100%">
			    <c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1}">
				<tr>
					<th  width="50%" ><div align="left">&nbsp;&nbsp;合同金额：<c:if test="${showLink=='Y'}"><a href="javascript:showEstBusCount();"></c:if>${salTotal}<c:if test="${showLink=='Y'}"></a></c:if></div></th>
					<th  width="50%" ><div align="left">&nbsp;&nbsp;回款金额：<c:if test="${showLink=='Y'}"><a href="javascript:showEstBackCount();"></c:if>${backTotal}<c:if test="${showLink=='Y'}"></a></c:if></div></th>
				</tr>
				</c:if>
				
				<tr>
					<td width="50%">
						<div align="left">
						&nbsp;&nbsp;------&nbsp;当期应收款：${busTotal}
						<br><br>
						&nbsp;&nbsp;------&nbsp;合同单数：${busCount}笔
						</div>
					</td>
					<td  width="50%">
						<div align="left">
						&nbsp;&nbsp;------&nbsp;预付金额：<c:if test="${showLink=='Y'}"><a href="javascript:showBackCostList('IMPREST');"></c:if>${impTotal}<c:if test="${showLink=='Y'}"></a></c:if>
						&nbsp;&nbsp;预付单数：<c:if test="${showLink=='Y'}"><a href="javascript:showBackCostList('IMPREST');"></c:if>${impCount}<c:if test="${showLink=='Y'}"></a></c:if>笔
						<br><br>
						&nbsp;&nbsp;------&nbsp;结欠金额：<c:if test="${showLink=='Y'}"><a href="javascript:showRecItemList();"></c:if>${recTotal}<c:if test="${showLink=='Y'}"></a></c:if>
						&nbsp;&nbsp;结欠单数：<c:if test="${showLink=='Y'}"><a href="javascript:showRecItemList();"></c:if>${recCount}<c:if test="${showLink=='Y'}"></a></c:if>笔
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div align="left">
						<br><br>
						<span class="give">注：1.  当期应收款：合同金额 – 预付金额   2.  结欠金额：收到之前业务单的欠款   3. 结欠单数：结欠的业务单单数</span>
						</div>
					</td>
				</tr>
			  </table>
			</div>
		
 		</div>
  </div>
<div>
</body>
</html>